﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Model.Extend.Models;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// MBOM同步到MES系统
    /// </summary>
    public class InterfaceBomMasterJob : IJobService
    {
        private readonly IInterfaceMasterRepository repository;


        public InterfaceBomMasterJob(IInterfaceMasterRepository _repository)
        {
            this.repository = _repository;
        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<SapBom_Extend> sapBoms = repository.GetBomMasterInfo();
                if (sapBoms.Count <= 0)
                {
                    return "没有待处理的BOM信息！";
                }

                bool bl = repository.InsertBomMasterInfo(sapBoms);

                if (bl == true)
                {
                    return "BOM信息同步成功！";
                }
                else
                {
                    return "BOM信息同步失败！";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("BOM信息同步错误！" + ex);
                return "BOM信息同步错误！" + ex.Message;
            }
        }



    }
}
